<script>
	export default {
		globalData: {},
		async onLaunch() {
			// console.log('App Launch！');
			const accountInfo = uni.getAccountInfoSync();
			this.$store.commit("setAccountInfo", {
				accountInfo,
			});

			const loginStorage = uni.getStorageSync('login');
			console.log("loginStorage = ", loginStorage);
			if (loginStorage.token) {
				this.$store.commit('login/setLoginInfo', {
					...this.$store.state.login,
					...loginStorage,
				});
			}
			// uni.hideTabBar();
			// uni.showTabBarRedDot({
			// 	index: 1,
			// })

			// 推送
			// const pushRes = await uni.getPushClientId();
			// console.log("pushRes: ", pushRes);
			// const msgRes = await uni.onPushMessage();
			// console.log("msgRes: ", msgRes);

		},
		onShow: function() {
			console.log('App Show');
			const updateManager = uni.getUpdateManager();

			updateManager.onCheckForUpdate(function(res) {
				// 请求完新版本信息的回调
				console.log("onCheckForUpdate:", res.hasUpdate);
				if (res && res.hasUpdate) {
					// 有新版本，优先
					uni.showLoading({
						title: '更新中...'
					})
				}
			});

			updateManager.onUpdateReady(function(res) {
				uni.hideLoading()
				uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好，是否重启应用？',
					success(res) {
						if (res.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});

			});

			updateManager.onUpdateFailed(function(res) {
				// 新的版本下载失败
				uni.showModal({
					title: '更新失败',
					content: '新版本更新失败，退出应用？',
					showCancel: false,
					success(res) {
						if (res.confirm) {
							uni.exitMiniProgram({
								success: function() {
									console.log('退出小程序成功');
								},
								fail: function(err) {
									console.log('退出小程序失败', err);
								}
							})
						}
					}
				});
			});
		},
		onHide: function() {
			console.log('App Hide');
		},
	};
</script>

<style lang="scss">
	/*公共css */
	@import '@/uni.scss';

	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';

	page {
		width: 100%;
		height: 100%;
		background-color: #f4f4f4 !important;
		// overflow: hidden;
	}

	.noData {
		width: 100%;
		height: 100%;
		background: $uni-bg-color;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		>image {
			width: 200rpx;
		}

		>text {
			margin-top: 10rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: $uni-extra-color;
		}
	}

	.noMore {
		margin-top: auto;
		width: 100%;
		height: fit-content;
		text-align: center;
		padding: 30rpx 0;
		color: #ccc;
		font-size: 24rpx;
	}

	::v-deep.uni-popup {
		z-index: 9999 !important;
	}

	button[type=default] {
		width: 690rpx;
		height: 96rpx;
		background: $uni-primary;
		box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(236, 95, 42, 0.2);
		border-radius: 48rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 36rpx;
		color: #ffffff;
		padding: 0;
		margin: 0;
	}

	button[disabled] {
		opacity: 0.5;
	}

	button::after {
		border: none;
	}

	.btnHover {
		background: $uni-primary-light !important;
	}

	.scaleAni {
		animation: scaleAni 1.5s linear infinite;
	}

	@keyframes scaleAni {
		0% {
			transform: scale(1);
		}

		50% {
			transform: scale(0.9);
		}

		100% {
			transform: scale(1);
		}
	}

	/* #endif */
</style>